! function () {
    var desk = window.location.search;
    var pageSize = 20,
    pagecurrent = 1,
    pageAll = null,
    target = null
    function getParams() {
        var str = desk.substr(1);
        var strA = str.split("&");
        var obj = {};
        if (!str) return
        for (var i = 0; i < strA.length; i++) {
            obj[strA[i].split("=")[0]] = JSON.parse(decodeURIComponent(strA[i].split("=")[1]))
        }
        return obj
    }
    if (getParams()) {
        var str = "";
        $.ajax({
            url: "http://localhost/80edu/api.php/records/detail",
            method: 'get',
            data: { filter: 'type,cs,' + getParams().matent },
            success: function (data) {
                $.each(data.records, function (k, v) {
                    str += '<div class="formTable">'
                        + '<div class="imgDivDiv fl">'
                        + '<img src="./img/22_20190510152040.png">'
                        + '</div>'
                        + '<div class="propList fl">'
                        + '<div class="productName propDiv">'
                        + v.name
                        + '</div>'
                        + '<div class="propDiv">'
                        + '编号：' + v.bianhao
                        + '</div>'
                        + '<div class="propDiv">'
                        + '类型： ' + v.leixing
                        + '</div>'
                        + '<div class="propDiv">'
                        + '规格： ' + v.guige
                        + '</div>'
                        + '<div class="propDiv">'
                        + '材质： ' + v.caizhi
                        + '</div>'
                        + '<div class="propDiv">'
                        + '品牌： ' + v.pinpai
                        + '</div>'
                        + '<div class="propDiv">'
                        + '型号： ' + v.xinghao
                        + '</div>'
                        + '<div class="propDiv">'
                        + '价格：<span>￥' + v.price + '</span>'
                        + '</div>'
                        + '<div class="propDiv">'
                        + '销量： ' + v.xiaoliang
                        + '</div>'
                        + '<div class="fk_first_mallBuy">'
                        + '立即购买'
                        + '</div>'
                        + '</div>'
                        + '</div>'
                })
                $('.Render-nup').html(str)
                $('.body-item-txt').text(getParams().matent)
                $('.right_nav span').text(getParams().matent)
            }
        })
    }else{
        treasureRender()
    }
    $('.left_Listers').on('click', '.Clicker', function (event) {
        console.log($(this).attr('data-text'))
        event.stopPropagation()
        location.href = "allbaby.html?matent=" +JSON.stringify($(this).attr('data-text')) 
    })
    $.ajax({
        url: "http://localhost/80edu/api.php/records/classify",
        type: "get",
        success: function (data) {
            var str = '',
                Nabmers = 1
            $.each(data.records, function (k, v) {
                if (v.pid == 0) {
                    Nabmers = 1
                    str += '<div class="ulDiv Clicker" data-text="' + v.title + '">' + v.title + ''
                    $.each(data.records, function (i, o) {
                        if (v.id == o.pid) {
                            if (Nabmers == 1) {
                                str += '<span class="right_icon iconfont icon-down"></span>'
                                Nabmers = undefined
                            }
                            str += '<div data-text="' + v.title + '" class="Clicker erjinav">' +
                                '<p >' + o.title + '</p>' +
                                '</div>'
                        }
                    })
                    str += '</div>'
                }
            })
            $('.left_Listers').html(str)
        }
    });

    function treasureRender() {
        $.ajax({
            url: 'http://localhost/80edu/api.php/records/detail',
            type: "get",
            data: {
                order: 'id,desc',
                page: pagecurrent + ',' + pageSize
            },
            success: function (data) {
                pageAll = data.results
                var str = '';
                $.each(data.records, function (k, v) {
                    str += '<div class="right_con_book fl clearfix">' +
                        '<i class="qwe"></i>' +
                        '<img src="./img/22_20190510152040.png">' +
                        '<p class="booksname">' + v.name + '</p>' +
                        '<p>编号：<span>' + v.bianhao + '</span></p>' +
                        '<p class="formerpic">市场价：<span>￥60.00</span></p>' +
                        '<p class="nowpic">价格：<span>￥' + v.price + '</span></p>' +
                        '<input type="hidden" value="' + v.id + '">' +
                        '<div class="header-purchase">立即购买</div>' +
                        '</div>'
                })
                $('.right_con').html(str)
                pageUl()
            }
        })
    }

    function pageUl() {
        target = Math.ceil(pageAll / pageSize),
            str = '';
        str += '<li class="pageUP">上一页</li>'
        for (i = 0; i < target; i++) {
            if ((i + 1) == pagecurrent) {
                str += '<li class="active">' + (i + 1) + '</li>'
            } else {
                str += '<li class="pageDown">' + (i + 1) + '</li>'
            }
        }
        str += '<li>下一页</li>'
        $('.right_page ul').html(str)
    }
    $('.right_page ul').on('click', 'li', function () {
        if ($(this).text() == "上一页") {
            if (pagecurrent == 1) {
                pagecurrent == 1
            } else {
                pagecurrent--
            }
        } else if ($(this).text() == "下一页") {
            if (pagecurrent == target) {
                pagecurrent == target
            } else {
                pagecurrent++
            }
        } else {
            pagecurrent = $(this).text()
        }
        treasureRender()
    })


    $('.right_con').on('click', '.header-purchase', function () {
        var Bookers = $(this).siblings('input').val()
        sessionStorage.setItem('Bookers', JSON.stringify(Bookers))
        location.href = 'particulars.html'
    })
}();